/**
 * 
 */
package com.bridgetree.jubaocrm.ui.groups;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bridgetree.jubaocrm.R;
import com.bridgetree.jubaocrm.util.Groups;

/**
 * GroupsAnnouncementActivity
 * </p>
 * 小组成员2014-5-20 上午11:21:00 create
 * 
 * @since 1.0
 */
public class GroupsMemberActivity extends Activity {
	private final String TAG = "GroupMainListActivity";

	private Context mContext;

	private ListView group_main_list = null;

	private GroupMainListAdapter mGroupMainListAdapter = null;

	private Groups mGroups;

	private ArrayList<String> proInfoListData = null;
	private ArrayList<String> proInfoListDataType = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.group_main_list);
		mContext = this;

		Intent intent = getIntent();
		if(intent == null) {
			Log.e(TAG, "intent is null");
			return;
		}

		TextView xm_bi_tv_title = (TextView) findViewById(R.id.xm_bi_tv_title);
		xm_bi_tv_title.setText("小组成员");
		if(intent.getExtras() != null) {
			mGroups = (Groups) intent.getExtras().getSerializable("groupsMain");
		}

		findViewById(R.id.xm_bi_RelativeLayout_back).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});

		group_main_list = (ListView) findViewById(R.id.group_main_list);
		proInfoListData = new ArrayList<String>();
		proInfoListData.add("小组成员");
		proInfoListData.add("查看非参与项目信息");
		proInfoListData.add("项目管理");
		proInfoListData.add("客户管理");
		proInfoListData.add("新报备项目审批");
		proInfoListData.add("客户独占保护管理");
		proInfoListData.add("资料复查");
		proInfoListData.add("人员管理");
		proInfoListData.add("离职管理");
		proInfoListData.add("公告发布");
		proInfoListData.add("终极项目审批");

		proInfoListDataType = new ArrayList<String>();
		proInfoListDataType.add("members");
		proInfoListDataType.add("view_all_projects");
		proInfoListDataType.add("edit_project");
		proInfoListDataType.add("edit_client");
		proInfoListDataType.add("approve_project");
		proInfoListDataType.add("exclusive_protect");
		proInfoListDataType.add("reviewers");
		proInfoListDataType.add("leaders");
		proInfoListDataType.add("manager_of_resign");
		proInfoListDataType.add("editors");
		proInfoListDataType.add("final_approve");
		//		case 100:
		//            groupMemberViewController.groupType = @"members"; // 小组成员
		//            break;
		//        case 101:
		//            groupMemberViewController.groupType = @"view_all_projects"; // 非参与项目
		//            break;
		//        case 102:
		//            groupMemberViewController.groupType = @"edit_project"; // 项目管理
		//            break;
		//        case 103:
		//            groupMemberViewController.groupType = @"edit_client"; // 客户管理
		//            break;
		//        case 104:
		//            groupMemberViewController.groupType = @"approve_project"; //新报备项目审批
		//            break;
		//        case 105:
		//            groupMemberViewController.groupType = @"exclusive_protect"; //客户独占保护管理
		//            break;
		//        case 106:
		//            groupMemberViewController.groupType = @"reviewers"; //资料复查
		//            break;
		//        case 107:
		//            groupMemberViewController.groupType = @"leaders"; //人员管理
		//            break;
		//        case 108:
		//            groupMemberViewController.groupType = @"manager_of_resign"; //离职管理
		//            break;
		//        case 109:
		//            groupMemberViewController.groupType = @"editors"; //公告发布
		//            break;
		//        case 110:
		//            groupMemberViewController.groupType = @"final_approve"; //终极项目审批
		//            break;

		mGroupMainListAdapter = new GroupMainListAdapter(mContext, proInfoListData);
		group_main_list.setAdapter(mGroupMainListAdapter);
		group_main_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
				Intent intent = new Intent(mContext, GroupsMemberChildActivity.class);
				Bundle bundle = new Bundle();
				bundle.putString("title", proInfoListData.get(arg2));
				bundle.putString("type", proInfoListDataType.get(arg2));
				bundle.putSerializable("groupsMain", mGroups);
				intent.putExtras(bundle);
				startActivity(intent);
			}

		});
	}

	class GroupMainListAdapter extends BaseAdapter {
		private ArrayList<String> DrugstoreDataList = null;
		private LayoutInflater listContainer; // 视图容器

		private class GridHolder {
			ImageView xm_12_flag_iv;
			TextView tv;
		}

		public GroupMainListAdapter(Context mContext, ArrayList<String> data) {
			this.DrugstoreDataList = data;
			listContainer = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		}

		@Override
		public int getCount() {
			if(DrugstoreDataList != null) {
				return DrugstoreDataList.size();
			}
			return 0;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return DrugstoreDataList.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			GridHolder holder;
			if (convertView == null) {
				convertView = listContainer.inflate(R.layout.xm_12_my_item, null);
				holder = new GridHolder();
				holder.xm_12_flag_iv = (ImageView) convertView.findViewById(R.id.xm_12_flag_iv);
				holder.tv = (TextView) convertView.findViewById(R.id.xm_12_item_tv);
				convertView.setTag(holder);
			} else {
				holder = (GridHolder) convertView.getTag();
			}

			final String xm_txt=DrugstoreDataList.get(position);
			holder.tv.setText(xm_txt);
			holder.xm_12_flag_iv.setVisibility(View.VISIBLE);
			if(xm_txt.equals("小组成员")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_member);
			}else if(xm_txt.equals("查看非参与项目信息")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_non_participation);
			}else if(xm_txt.equals("项目管理")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_folder);
			}else if(xm_txt.equals("客户管理")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_client);
			}else if(xm_txt.equals("新报备项目审批")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_checking);
			}else if(xm_txt.equals("客户独占保护管理")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_lock);
			}else if(xm_txt.equals("资料复查")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_review);
			}else if(xm_txt.equals("人员管理")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_manage_user);
			}else if(xm_txt.equals("离职管理")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_cut);
			}else if(xm_txt.equals("公告发布")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_horn);
			}else if(xm_txt.equals("终极项目审批")){
				holder.xm_12_flag_iv.setImageResource(R.drawable.ico_final);
			}
			return convertView;
		}

	}
}
